﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.ComponentModel;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class UIKDADR : ViewBase
    { 

        public UIKDADR()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
         }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwKDR = dwMaster;
            if (dwMaster == null)
            {
                KEY = "";
                //KDAADRSL = "";
            }
            else
            {
                KDAADRSL = dwMaster["KDAADRSL"].ToString();
                KEY = (dwMaster["KDAKUNDNR"].ToString() + dwMaster["KDAADRSL"].ToString()).PadRight(16);
            }

        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }

        public virtual void OnKUNDNRChg(string value)
        { 
        } 
    }

    public partial class UIKDADR : ViewBase
    {
        public VKUNDADR TMV
        {
            get
            {
                return (VKUNDADR)MV;
            }
        }
        #region ==KUNDNR===========
        public static readonly DependencyProperty KUNDNRProperty = DependencyProperty.Register("KUNDNR",
            typeof(string), typeof(UIKDADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKUNDNRChanged));
        public string KUNDNR
        {
            get
            {
                return (string)GetValue(KUNDNRProperty);
            }
            set
            {
                SetValue(KUNDNRProperty, value);
                OnKUNDNRChg(value);
            }
        }
        private static void OnKUNDNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKDADR;
            if (src != null)
            {
                src.KUNDNR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDAADRSL===========
        public static readonly DependencyProperty KDAADRSLProperty = DependencyProperty.Register("KDAADRSL",
            typeof(string), typeof(UIKDADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDAADRSLChanged));
        public string KDAADRSL
        {
            get
            {
                return (string)GetValue(KDAADRSLProperty);
            }
            set
            {
                SetValue(KDAADRSLProperty, value.PadRight(8));
            }
        }
        private static void OnKDAADRSLChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKDADR;
            if (src != null)
            {
                src.KDAADRSL = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDANAME1===========
        public static readonly DependencyProperty KDANAME1Property = DependencyProperty.Register("KDANAME1",
            typeof(string), typeof(UIKDADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDANAME1Changed));
        public string KDANAME1
        {
            get
            {
                return (string)GetValue(KDANAME1Property);
            }
            set
            {
                SetValue(KDANAME1Property, value);
                if (MV == null)
                    return;
                if (dwMaster == null)
                    return;
                TMV.KDANAME1 = value;
            }
        }
        private static void OnKDANAME1Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKDADR;
            if (src != null)
            {
                src.KDANAME1 = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDANAME2===========
        public static readonly DependencyProperty KDANAME2Property = DependencyProperty.Register("KDANAME2",
            typeof(string), typeof(UIKDADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDANAME2Changed));
        public string KDANAME2
        {
            get
            {
                return (string)GetValue(KDANAME2Property);
            }
            set
            {
                SetValue(KDANAME2Property, value);
                if (MV == null)
                    return;
                if (dwMaster == null)
                    return;
                TMV.KDANAME2 = value;
            }
        }
        private static void OnKDANAME2Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKDADR;
            if (src != null)
            {
                src.KDANAME2 = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDASTRASSE1===========
        public static readonly DependencyProperty KDASTRASSE1Property = DependencyProperty.Register("KDASTRASSE1",
            typeof(string), typeof(UIKDADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDASTRASSE1Changed));
        public string KDASTRASSE1
        {
            get
            {
                return (string)GetValue(KDASTRASSE1Property);
            }
            set
            {
                SetValue(KDASTRASSE1Property, value);
                if (MV == null)
                    return;
                if (dwMaster == null)
                    return;
                TMV.KDASTRASSE1 = value;
            }
        }
        private static void OnKDASTRASSE1Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKDADR;
            if (src != null)
            {
                src.KDASTRASSE1 = (string)e.NewValue;
            }
        }
        #endregion
        #region ==KDASTRASSE2===========
        public static readonly DependencyProperty KDASTRASSE2Property = DependencyProperty.Register("KDASTRASSE2",
            typeof(string), typeof(UIKDADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDASTRASSE2Changed));
        public string KDASTRASSE2
        {
            get
            {
                return (string)GetValue(KDASTRASSE2Property);
            }
            set
            {
                SetValue(KDASTRASSE2Property, value);
                if (MV == null)
                    return;
                if (dwMaster == null)
                    return;
                TMV.KDASTRASSE2 = value;
            }
        }
        private static void OnKDASTRASSE2Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKDADR;
            if (src != null)
            {
                src.KDASTRASSE2 = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDATEL===========
        public static readonly DependencyProperty KDATELProperty = DependencyProperty.Register("KDATEL",
            typeof(string), typeof(UIKDADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDATELChanged));
        public string KDATEL
        {
            get
            {
                return (string)GetValue(KDATELProperty);
            }
            set
            {
                SetValue(KDATELProperty, value);
                if (MV == null)
                    return;
                if (dwMaster == null)
                    return;
                TMV.KDATEL = value;
            }
        }
        private static void OnKDATELChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKDADR;
            if (src != null)
            {
                src.KDATEL = (string)e.NewValue;
            }
        }
        #endregion
        #region ==KDAPOSTFACH===========
        public static readonly DependencyProperty KDAPOSTFACHProperty = DependencyProperty.Register("KDAPOSTFACH",
            typeof(string), typeof(UIKDADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDAPOSTFACHChanged));
        public string KDAPOSTFACH
        {
            get
            {
                return (string)GetValue(KDAPOSTFACHProperty);
            }
            set
            {
                SetValue(KDAPOSTFACHProperty, value);
                if (MV == null)
                    return;
                if (dwMaster == null)
                    return;
                TMV.KDAPOSTFACH = value;
            }
        }
        private static void OnKDAPOSTFACHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKDADR;
            if (src != null)
            {
                src.KDAPOSTFACH = (string)e.NewValue;
            }
        }
        #endregion
        #region ==KDATTEX===========
        public static readonly DependencyProperty KDATTEXProperty = DependencyProperty.Register("KDATTEX",
            typeof(string), typeof(UIKDADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDATTEXChanged));
        public string KDATTEX
        {
            get
            {
                return (string)GetValue(KDATTEXProperty);
            }
            set
            {
                SetValue(KDATTEXProperty, value);
                if (MV == null)
                    return;
                if (dwMaster == null)
                    return;
                TMV.KDATTEX = value;
            }
        }
        private static void OnKDATTEXChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKDADR;
            if (src != null)
            {
                src.KDATTEX = (string)e.NewValue;
            }
        }
        #endregion


        #region ==KDAFAX===========
        public static readonly DependencyProperty KDAFAXProperty = DependencyProperty.Register("KDAFAX",
            typeof(string), typeof(UIKDADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDAFAXChanged));
        public string KDAFAX
        {
            get
            {
                return (string)GetValue(KDAFAXProperty);
            }
            set
            {
                SetValue(KDAFAXProperty, value);
                if (MV == null)
                    return;
                if (dwMaster == null)
                    return;
                TMV.KDAFAX = value;
            }
        }
        private static void OnKDAFAXChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKDADR;
            if (src != null)
            {
                src.KDAFAX = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDAMAILADR===========
        public static readonly DependencyProperty KDAMAILADRProperty = DependencyProperty.Register("KDAMAILADR",
            typeof(string), typeof(UIKDADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDAMAILADRChanged));
        public string KDAMAILADR
        {
            get
            {
                return (string)GetValue(KDAMAILADRProperty);
            }
            set
            {
                SetValue(KDAMAILADRProperty, value);
                if (MV == null)
                    return;
                if (dwMaster == null)
                    return;
                TMV.KDAMAILADR = value;
            }
        }
        private static void OnKDAMAILADRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKDADR;
            if (src != null)
            {
                src.KDAMAILADR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwKDR===========
        public static readonly DependencyProperty dwKDRProperty = DependencyProperty.Register("dwKDR",
            typeof(DataRow), typeof(UIKDADR),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwKDRChanged));
        public DataRow dwKDR
        {
            get
            {
                return (DataRow)GetValue(dwKDRProperty);
            }
            set
            {
                SetValue(dwKDRProperty, value);
            }
        }
        private static void OdwKDRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKDADR;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwKDR = row;
            }
        }
        #endregion
    }
}